<!--
 * @name: 
 * @Author: 刘大可
 * @Date: 2023-02-09 17:26:42
 * @LastEditors: 刘大可
 * @LastEditTime: 2023-04-13 09:45:14
-->
<template>
    <view class="gcNavList row">
        <!-- {{ navlist.length }} -->
        <!-- {{ JSON.stringify(navlist) }} -->
        <block v-for="(item,index) in navlist" :key="index">
            <view class="nav flex-col" @click="jump"
            :data-urltype="item.types" :data-type="index + 1"
            :data-url="item.appid" :data-id="item.id" :data-appid="item.appid"
            >
                <image
                    class="icon"
                    :src="item.image"
                    mode="scaleToFill"
                />
                {{ item.title }}
                <!-- {{ item.types}} -->
            </view>
        </block>
       <!-- <view>
            <block v-for="(item, index) in navlist" :key="index">
                <view>
                    {{ item.appid }}
                </view>
            </block>
       </view> -->
    </view>
</template>
<script>
let app=getApp()
export default {
    data() {
        return {
            modules_load:true
        }
    },
    props: {
        navlist: {
            type: [Array, Object, String],
            default() {
                return [];
            }
        }
    },
    created() {
        console.log("navlist",this.navlist);
    },
    methods: {
        jump(e){
            console.log(e.currentTarget.dataset);
            // console.log(item.types != 2);
            // return 
            if (e.currentTarget.dataset.urltype !=2) {
                this.onJsEvent(e)
            }else{
                this.toOther(e)
            }
        },
        async onJsEvent(e) {
            console.log("打印值", e.currentTarget.dataset)
            // console.log(e)
            if (e.currentTarget.dataset.url.indexOf('h5/index') > -1) {
                await this.login().then((res) => {
                    console.log("您已登陆！");
                })
            }
            // console.log(e.currentTarget.dataset.url);
            console.log('是否加载完毕', this.modules_load);
            if (this.modules_load) {
                //后台配置内容
                if (e.currentTarget.dataset.url != " ") {
                    if (e.currentTarget.dataset.urltype == 0) {
                        uni.setStorageSync('module_id', e.currentTarget.dataset.id)
                        if (e.currentTarget.dataset.url.indexOf('gc_school/pages/article/list') > -1) {
                            this.goArticle(e.currentTarget.dataset.url)
                            return false
                        }
                        console.log('这里是状态2221111', e.currentTarget.dataset.url)
                        if (e.currentTarget.dataset.url == 'zby' || e.currentTarget.dataset.url == 'food' || e.currentTarget.dataset.url == 'digital' || e.currentTarget.dataset.url == 'dianying') {
                            console.log('这里是状态222')
                            if (e.currentTarget.dataset.url == 'dianying') {
                                if (!uni.getStorageSync('token')) {
                                    uni.navigateTo({
                                        url: '/gc_school/pages/login/login'
                                    })
                                }
                                app.globalData.util.request({
                                    url: 'WechatUser/users',
                                    data: {
                                    },
                                    success: (res) => {
                                        this.dyu_id = res.data.data.u_id;
                                        var dyu_ids = res.data.data.u_id
                                        // console.log(res.data.data.u_id,'用户信息')
                                        var dydata = this.sys.pub_id + "&channel=" + uni.getStorageSync('schoolId') + ',' + dyu_ids
                                        console.log(dydata, '数据获取')
                                        uni.navigateTo({
                                            url: "plugin-private://wx89752980e795bfde/pages/index/index?pub_id=" + dydata
                                        });
                                    }
                                }, true)


                            } else {
                                uni.navigateTo({
                                    url: '/pages/openwebview/openwebview?types=1&url_type=' + e.currentTarget.dataset.url
                                })
                            }

                        } else {
                            // uni.navigateTo({
                            //     url: e.currentTarget.dataset.url + '&id=' + e.currentTarget.dataset.id
                            // })
							
							let isCourse = e.currentTarget.dataset.url.indexOf('/canteen/canteen')
							if(isCourse > -1){
								uni.switchTab({
								    url: e.currentTarget.dataset.url + '&id=' + e.currentTarget.dataset.id
								})
							}else{
								uni.navigateTo({
								    url: e.currentTarget.dataset.url + '&id=' + e.currentTarget.dataset.id
								})
							}
                        }
                    } else {
                        let isCourse = e.currentTarget.dataset.url.indexOf('gc-curriculum')
                        console.log(e.currentTarget.dataset.url);
                        console.log(isCourse);
                        if (isCourse > -1) {
                            await this.dingyueKeBiao()

                        }
                        uni.navigateTo({
                            url: '/gc_school/pages/webview/index?url=' + encodeURIComponent(e.currentTarget.dataset.url)

                        })
                    }
                } else {
                    uni.setStorageSync('module_id', 0)
                    if (e.currentTarget.dataset.type == 3) {
                        uni.switchTab({
                            url: '/gc_school/pages/canteen/canteen'
                        })
                    } else {
                        uni.navigateTo({
                            url: '/gc_school/pages/public/index?type=' + e.currentTarget.dataset.type +
                                '&id=' + e.currentTarget.dataset.id
                        })
                    }
                }
            }
        },
        goArticle(url = "") {
            console.log(url);
            let class_id = url.split("class_id=")[1].split("&")[0]
            console.log(class_id);
            var that = this;
            app.globalData.util.request({
                url: 'ZhForumClass/view',
                method: 'POST',
                data: {
                    class_id
                },
                success(res) {
                    console.log(res);
                    let item = res.data.data
                    that.toList(1, item.class_id, item.is_auth_watch, item.url, item.class_name)
                }
            }, true);

        },

          toList(type, id, auth, url, name) {
            if (type == 1) {
                var urls = '/gc_school/pages/article/list?class_id=' + id + '&class_name=' + name
            }
            else {
                var urls = '/gc_school/pages/article/detail?id=' + id
            }
            console.log(name)
            if (url) {
                uni.navigateTo({
                    url: url
                })
            }
            else {
                if (auth == 0) {
                    uni.navigateTo({
                        url: urls
                    })
                }
                //需要认证的分类
                else {
                    //没有认证过，提示去认证
                    if (this.authData.status == 0) {
                        uni.showModal({
                            title: '温馨提示',
                            content: '本内容只对本校认证学生查看，请先认证！',
                            success(res) {
                                if (res.confirm) {
                                    uni.navigateTo({
                                        url: '/gc_school/pages/user/student'
                                    })
                                } else {
                                    console.log('取消删除');
                                }
                            }
                        });
                    }
                    else {
                        //判断是否和当前一个学校
                        if (this.authData.data.s_id != uni.getStorageSync('schoolId')) {
                            uni.showToast({
                                title: '您好，本内容只对本校认证学生查看，您暂无权限。',
                                icon: 'none',
                                duration: 3000
                            })
                        }
                        else {
                            if (this.authData.data.state == 0) {
                                uni.showToast({
                                    title: '请等待审核结果',
                                    icon: 'none',
                                    duration: 3000
                                })
                            } else if (this.authData.data.state == 2) {
                                uni.navigateTo({
                                    url: '/gc_school/pages/user/student'
                                })
                            } else {
                                uni.navigateTo({
                                    url: urls
                                })
                            }
                        }
                    }
                }
            }

        },
        //跳转其他小程序
        toOther(e) {
            console.log(e.currentTarget.dataset);
            
            let appId = e.currentTarget.dataset.appid.split(';')[0]
            let path = e.currentTarget.dataset.appid.split(';')[1] || ""

            console.log(appId);
            console.log(path);
            uni.openEmbeddedMiniProgram({
                // uni.navigateToMiniProgram({
                appId,
                path,
                extraData: {
                    foo: 'bar'
                },
                // envVersion: 'release',
                success(res) {
                    // 打开成功
                    console.log('打开成功');
                }
            });
        },
    },
}
</script>
<style lang="scss">
    @import "./main.scss";
</style>